﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SqlLibrary;
using AgencyEntityLib.BaseEntity;
using Ecopsy.DataTier;

public partial class Ctl_ctlFilterList : ImFilter 
{
    public Func <ListWhere, bool> OnApp_Click;
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public string btnSave_ClientID { get { return btnSave.ClientID.Replace("_", "$"); } }

    public string BtnCancel_ClientID { get { return btnClose.ClientID.Replace("_", "$"); } }

    public void MyDataBind()
    {
        GlobalConstants.CurrentEmployeer.FilterList.Reset();
        lvUserFilters.DataSource = GlobalConstants.CurrentEmployeer.FilterList.GetFilterList(this.FilterType,this .AddKey) ;
        lvUserFilters.DataBind();

        lvCommonFilters.DataSource = GlobalConstants.CurrentAgency.FilterList.GetFilterList(this.FilterType, this.AddKey);
        lvCommonFilters.DataBind();

    }




    protected void AppUserFilter_Click(object sender, EventArgs e)
    {
        LinkButton b= (LinkButton )sender ;        
        Filter f = (Filter)GlobalConstants.CurrentEmployeer.FilterList[b.CommandArgument];        
        
        if (null != OnApp_Click)
            OnApp_Click((ListWhere)f.Value.Clone());        
        

    }
    protected void AppCommonFilter_Click(object sender, EventArgs e)
    {
        LinkButton b= (LinkButton )sender ;        
        Filter f = (Filter)GlobalConstants.CurrentAgency.FilterList[b.CommandArgument];
        ListWhere w = (ListWhere)f.Value.Clone();
        if (null != OnApp_Click)
                    OnApp_Click(w);
        
    }



    protected void btnUserFilterDelete_Click(object sender, ImageClickEventArgs e)
    {
        ImageButton b = (ImageButton)sender;
        Employeer empl = GlobalConstants.CurrentEmployeer;
        empl.FilterList.Remove(b.CommandArgument);
        wsFace ws = (wsFace)GlobalConstants.CurrentAgency.WS_FactoryList[WS_FactoryList.wsKey_Face];
        ws.SaveFace(empl);
        wsAgency.Reset();
        MyDataBind();
        

    }
    protected void btnCommonFilterDelete_Click(object sender, ImageClickEventArgs e)
    {
        ImageButton b = (ImageButton)sender;
        GlobalConstants.CurrentAgency.FilterList.Remove(b.CommandArgument);
        wsAgency ws = new wsAgency();
        ws.SaveAgency();
        wsAgency.Reset();
        MyDataBind();
     

    }
}
